#!/usr/bin/python
# author: yoshiii.yoshiii@googlemail.com
# you found this code on http://yoshiii-box.googlecode.com/svn/ 
#

import os, sys
import getopt
from socket import *

# initialize, parse and set options
verbose = False
options, args = getopt.getopt(sys.argv[1:], 'v')
for o,a in options:
	if o in ['-v']: verbose = True

host = gethostbyname(args[0])
port = int(args[1])

print "connecting to", host, "port", port
sock = socket(AF_INET, SOCK_STREAM)
sock.connect((host, port))

EOF = False
line_counter = 0
while not EOF:
	try:
		line = raw_input()
		if verbose: print line
		else:
			line_counter += 1
			sys.stdout.write("\b\b\b\b\b\b\b\b\b%9i"%line_counter)
		sys.stdout.flush()
		# transmitt line to socket.
		sock.send(line+'\n')
	except EOFError:
		sock.close()
		EOF = True
	except KeyboardInterrupt:
		sock.close()
		EOF = True


